import UserGameData from "./UserGameData";
import RankModel from "./RankModel";
import DataEvent from "./DataEvent";

const { ccclass, property } = cc._decorator;

@ccclass
export default class RankItem extends cc.Component {

    @property(cc.Label)
    label_name: cc.Label = null;

    @property(cc.Label)
    label_score: cc.Label = null;

    @property(cc.Label)
    label_num: cc.Label = null;

    @property(cc.Sprite)
    icon: cc.Sprite = null;


    start() {
    }

    init(user: RankModel, rank: number) {
        // console.log(' init ============================== ', user)
        // set nickName
        this.label_name.string = user.getNickName()
        this.label_num.string = "" + rank

        this.label_score.string = user.getScore() + DataEvent.FONT;

        // set avatar
        cc.loader.load({ url: user.getAwatarUrl(), type: 'png' }, (err, texture) => {
            if (err || !this.node) {
                console.error(err);
                return;
            }

            this.icon.spriteFrame = new cc.SpriteFrame(texture);
        });
    }

    // update (dt) {}
}
